package com.lc.afbx.adapters;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiShouXianProduct;

import java.util.List;

/**
 * Created by Administrator on 2016/7/5.
 */
public class ProductAdapter2 extends BaseAdapter {

    private Context context;
    private List<GetApiShouXianProduct.Data> list;

    public ProductAdapter2(Context context, List<GetApiShouXianProduct.Data> dataList) {
        this.context = context;
        this.list = dataList;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {

            convertView = LayoutInflater.from(context).inflate(R.layout.item_product_ywx, null);
            BaseApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);
            holder = new ViewHolder();
            holder.img = (SimpleDraweeView) convertView.findViewById(R.id.img);
            holder.title = (TextView) convertView.findViewById(R.id.title);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.title.setText(list.get(position).title);
        holder.img.setImageURI(Uri.parse(list.get(position).picurl));


        return convertView;
    }

    private class ViewHolder {

        SimpleDraweeView img;

        TextView title;
    }
}
